package com.dubbo.util;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class FileReadWriteUtil {

    public static void writeFileMap(String fileName, List<String> jsonParamList){

        try {
            File writeName = new File(fileName);
            writeName.createNewFile();
            try (FileWriter writer = new FileWriter(writeName, false);
                 BufferedWriter out = new BufferedWriter(writer)){
                for(String json:jsonParamList) {
                    out.write(json);
                    out.newLine();   // 换行
                }
                out.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static List<String> readFileString(String fileName) throws IOException {
        List<String> res=new ArrayList<>();
        File file=new File(fileName);
        if(!file.exists()){
            return null;
        }
        try(BufferedReader in = new BufferedReader(new FileReader(file))) {
            String str;
            while ((str = in.readLine()) != null) {
                res.add(str);
            }
            return res;
        }
    }
}
